package com.jvm;

import org.springframework.util.StringUtils;

import java.io.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-11-17 13:53
 *
 * -XX:StringTableSize=10000
 */
public class StringTableDemo03 {

    public static void main(String[] args) throws Exception{


        List<String> words = new LinkedList<>();
        long start = System.currentTimeMillis();

        for (int i = 0; i < 2; i++) {

            FileInputStream inputStream = new FileInputStream(new File("/Users/apple/Documents/tmp8/linux.words"));

//            BufferedReader bufferedReader = new BufferedReader(new FileReader("/Users/apple/Documents/tmp8/linux.words"));
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while (true) {


                String line = bufferedReader.readLine();

                if (StringUtils.isEmpty(line)) {

                    break;
                }

                // 把字符串放入到字符串常量池中，只使用常量池中的一份即可，字符串表类似使用hashmap。有一个size来表示其中的bluckit大小，使用 jvm 参数 StringTableSize来表示
                words.add(line);
            }
        }

        System.out.println(System.currentTimeMillis() - start);
        TimeUnit.SECONDS.sleep(40);

        for (int i = 0; i < 1000; i++) {

            System.out.println(words.get(i));
        }
    }

}
